﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using zsi.Framework.Data;
using zsi.Framework.Data.DataProvider.SQLServer;
using zsi.ECommerce.Models;
using System.Data;
using System.Data.SqlClient;
using zsi.ECommerce.Util;
using System.Web.Mvc;
using zsi.Framework.Security;
namespace zsi.ECommerce.Models.DataControllers
{
    public class dcUser : MasterDataController<User>
    {
        public override void InitDataController()
        {
            this.DBConn = new SqlConnection(DBConnection.ConnectionString);

            this.Procedures.Add(new Procedure("dbo.SelectUsers", SQLCommandType.GetSingleInfo));
            this.Procedures.Add(new Procedure("dbo.SelectUsers", SQLCommandType.Select));
            this.Procedures.Add(new Procedure("dbo.UpdateUsers", SQLCommandType.Update));
        }

        public List<User> GetPoliceVerifiers(int CityMunicipalityId)
        {
            try
            {
                this.SelectParameters.Add("p_CityMunicipalityId",CityMunicipalityId);
                this.SelectParameters.Add("p_RoleType","PV");
                return this.GetDataSource();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<User> GetPoliceApprovers(int CityMunicipalityId)
        {
            try
            {
                this.SelectParameters.Add("p_CityMunicipalityId", CityMunicipalityId);
                this.SelectParameters.Add("p_RoleType", "PC");
 
                return this.GetDataSource();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

 
 

        public User GetUserLogon(string UserName)
        {
            try
            {
                Procedure p = new Procedure("dbo.SelectLogon");
                p.Parameters.Add("p_UserName", UserName);
                return new dcUser().GetInfo(p);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public User GetUserInfo(string Parameter, object Value)
        {
            try
            {
                this.SelectInfoParameters.Add(Parameter, Value);
                return this.GetInfo();
            }
            catch (Exception ex) {
                throw ex;
            }
        }

        public User GetUserInfo(string ClientRequestCode) {
            try
            {
                Cryptography _crypt = new Cryptography();
                dcUser _dc = new dcUser();
                Procedure _p = new Procedure("dbo.SelectClientRequestCode");
                //ClientRequestCode = System.Web.HttpUtility.UrlDecode(ClientRequestCode);               
                _p.Parameters.Add("p_ClientRequestCode", ClientRequestCode);
                return _dc.GetInfo(_p);
            }catch{            
                return new User();
            } 
        }


    }

}
